function WebGLShader()
{
	this.shaderProgram = null;
	this.vertexPositionAttribute = null;
	this.textureCoordAttribute = null;		
}
	
//
// initShaders
//
// Initialize the shaders, so WebGL knows how to light our scene.
//
WebGLShader.prototype.initShaders = function(gl) 
{
  var fragmentShader = this.getShader(gl, "shader-fs");
  var vertexShader = this.getShader(gl, "shader-vs");
  
  // Create the shader program
  
  this.shaderProgram = gl.createProgram();
  gl.attachShader(this.shaderProgram, vertexShader);
  gl.attachShader(this.shaderProgram, fragmentShader);
  gl.linkProgram(this.shaderProgram);
  
  // If creating the shader program failed, alert
  
  if (!gl.getProgramParameter(this.shaderProgram, gl.LINK_STATUS)) 
  {
	alert("Unable to initialize the shader program.");
  }
  
  gl.useProgram(this.shaderProgram);
  
  this.vertexPositionAttribute = gl.getAttribLocation(this.shaderProgram, "aVertexPosition");
  gl.enableVertexAttribArray(this.vertexPositionAttribute);
  
  this.textureCoordAttribute = gl.getAttribLocation(this.shaderProgram, "aTextureCoord");
  gl.enableVertexAttribArray(this.textureCoordAttribute);
}

//
// getShader
//
// Loads a shader program by scouring the current document,
// looking for a script with the specified ID.
//
WebGLShader.prototype.getShader = function(gl, id) 
{
  var shaderScript = document.getElementById(id);
  
  // Didn't find an element with the specified ID; abort.
  
  if (!shaderScript) 
  {
	return null;
  }
  
  // Walk through the source element's children, building the
  // shader source string.
  
  var theSource = "";
  var currentChild = shaderScript.firstChild;
  
  while(currentChild) 
  {
	if (currentChild.nodeType == 3)
	{
	  theSource += currentChild.textContent;
	}
	
	currentChild = currentChild.nextSibling;
  }
  
  // Now figure out what type of shader script we have,
  // based on its MIME type.
  
  var shader;
  
  if (shaderScript.type == "x-shader/x-fragment") 
  {
	shader = gl.createShader(gl.FRAGMENT_SHADER);
  } 
  else if (shaderScript.type == "x-shader/x-vertex")
  {
	shader = gl.createShader(gl.VERTEX_SHADER);
  } 
  else 
  {
	return null;  // Unknown shader type
  }
  
  // Send the source to the shader object
  
  gl.shaderSource(shader, theSource);
  
  // Compile the shader program
  
  gl.compileShader(shader);
  
  // See if it compiled successfully
  
  if (!gl.getShaderParameter(shader, gl.COMPILE_STATUS))
  {
	alert("An error occurred compiling the shaders: " + gl.getShaderInfoLog(shader));
	return null;
  }
  
  return shader;
}	


